
/**
 *
 * 覆盖PfBillEventHandler中的方法
 
 * 单据的弃审操作(反审暂不支持批处理)
 */
function jkbxUnApprove()
{
	log("PF--->弃审时单据状态不同继续执行!");	
	showProgressDialog(trans('ml_wait'));
	var headDs = this.getMasterDs();
	var rows = headDs.getSelectedRows();
	if(rows == null )
		showMessageDialog(trans('ml_noselrow'));
	if(this.beforeAction(IPfAction.UNAPPROVE) == false)
		return;
	var indices = headDs.getSelectedIndices(); 
	
	var count = indices.length;
    var arr = new Array();//主ds的pk数组
	var pkindex = getDatasetMasterKeyField(headDs);
	var djdl = null;;
	var djdlIndex = headDs.nameToIndex('djdl');
    for(var i = count - 1 ; i >= 0; i--){
    	var sRow = headDs.getRow(indices[i]); 
    	arr.push(sRow.getCellValue(pkindex));
    	djdl = sRow.getCellValue(djdlIndex);
    }
	var cmd = new CommonCommand("unApproveByPks");
    cmd.setParameter("delpks=" + arr.join('$') + "&djdl=" + djdl);
    //this代表PFBillEventHandler的实例
    cmd.setReturnArgs([headDs,this,indices]);
    cmd.setReturnFunc(JkbxUnApproveReturnFun);
    cmd.setCallObj(this);
    cmd.exec();
	
};

/**
 * 单据弃审的回调函数
 */
function JkbxUnApproveReturnFun(xml, returnArgs, isSuccess)
{
	hideProgressDialog();
	if(isSuccess){
		var headDs = returnArgs[0], oThis = returnArgs[1], indices = returnArgs[2];
		setCheckMan(headDs);//用来更新‘修改’按钮状态
		updateUnApproveStatus(headDs, xml, indices);
		if(oThis.afterAction(IPfAction.UNAPPROVE) == false)
			return;
	}
};

function updateUnApproveStatus(headDs,xmldoc,allDelIndice){
	var maps = parseXmlToMaps(xmldoc);
	var pkIndex = getDatasetMasterKeyField(headDs);
	for(var i=0; i<allDelIndice.length; i++){
		var rowIndex = allDelIndice[i];
		var row = headDs.getRow(rowIndex);
		var pk = row.getCellValue(pkIndex);
		if(maps[0].containsKey(pk)){//成功
			var v = maps[0].get(pk).split('$');
			headDs.setValueAt(rowIndex,headDs.nameToIndex('djzt'),v[1]);
			headDs.setValueAt(rowIndex,headDs.nameToIndex('spzt'),v[2]);
			headDs.setValueAt(rowIndex,headDs.nameToIndex('qcbz'),v[3]);
			headDs.setValueAt(rowIndex,headDs.nameToIndex('sxbz'),v[4]);
			headDs.setValueAt(rowIndex,headDs.nameToIndex('shr'), v[5],true);
			headDs.setValueAt(rowIndex,headDs.nameToIndex('shrq'),v[6]);
			headDs.setValueAt(rowIndex,headDs.nameToIndex('ts'),v[7]);
			headDs.setValueAt(rowIndex,headDs.nameToIndex('jsrq'),v[8]);
			
			billUI.eventHandler.callAllDsClearStatus();
			var billStatus = billUI.eventHandler.getBillStatus(headDs, row);
			billUI.setTotalUIStatus(IBillOperate.OP_NOTEDIT, billStatus);	
		}
	}	
	
}

